import 'package:flutter/material.dart';

class TaskItem extends StatefulWidget {
  TaskItem({super.key, this.desc, required this.taskItem});
  String? desc = '提货';
  Map taskItem;

  @override
  State<TaskItem> createState() => _TaskItemState();
}

class _TaskItemState extends State<TaskItem> {
  String? desc = '提货';
  Map taskItem = {};

  @override
  void initState() {
    super.initState();
    setState(() {
      if (widget.desc != null) desc = widget.desc;
      taskItem = widget.taskItem;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 230,
      width: 345,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10),
      ),
      padding: EdgeInsets.only(left: 20, top: 15, right: 13, bottom: 18.5),
      child: Column(
        children: [
          // 任务编号
          Row(
            children: [
              Expanded(
                child: Text(
                  // '任务编号：XAHH1234567',
                  '任务编号：${taskItem['transportTaskId']}',
                  style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
                ),
              ),
              !taskItem['enablePickUp']
                  ? Container(
                      width: 52,
                      padding: EdgeInsets.only(bottom: 3),
                      decoration: BoxDecoration(
                          border: Border.all(color: Colors.red[400]!, width: 1),
                          borderRadius: BorderRadius.circular(11)),
                      child: Text(
                        '已延迟',
                        textAlign: TextAlign.center,
                        style: TextStyle(fontSize: 12, color: Colors.red[400]),
                      ),
                    )
                  : Text('')
            ],
          ),

          // 始末点信息
          Container(
            margin: EdgeInsets.only(top: 21, bottom: 14.5),
            padding: EdgeInsets.only(bottom: 22.5),
            decoration: BoxDecoration(
                border: Border(
                    bottom: BorderSide(color: Colors.grey[400]!, width: 1))),
            height: 95,
            child: Row(
              spacing: 11.5,
              children: [
                // 左侧
                Column(
                  children: [
                    Container(
                      width: 22,
                      height: 22,
                      decoration: BoxDecoration(
                          color: Colors.black,
                          borderRadius: BorderRadius.circular(11)),
                      child: Text(
                        '起',
                        textAlign: TextAlign.center,
                        style: TextStyle(color: Colors.white, fontSize: 12),
                      ),
                    ),
                    Spacer(),
                    Container(
                      width: 1,
                      height: 4,
                      color: Colors.grey[400],
                    ),
                    Spacer(),
                    Container(
                      width: 1,
                      height: 4,
                      color: Colors.grey[400],
                    ),
                    Spacer(),
                    Container(
                      width: 1,
                      height: 4,
                      color: Colors.grey[400],
                    ),
                    Spacer(),
                    Container(
                      width: 22,
                      height: 22,
                      decoration: BoxDecoration(
                          color: Colors.red,
                          borderRadius: BorderRadius.circular(11)),
                      child: Text(
                        '止',
                        textAlign: TextAlign.center,
                        style: TextStyle(color: Colors.white, fontSize: 12),
                      ),
                    ),
                  ],
                ),

                // 右侧
                Expanded(
                    child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                      Text(
                        taskItem['startAddress'],
                        maxLines: 2,
                        style: TextStyle(fontSize: 14, color: Colors.grey[400]),
                      ),
                      Spacer(),
                      Text(
                        taskItem['endAddress'],
                        maxLines: 2,
                        style: TextStyle(fontSize: 14, color: Colors.grey[400]),
                      ),
                    ]))
              ],
            ),
          ),

          // 提货时间
          Row(children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '提货时间',
                  style: TextStyle(fontSize: 14, color: Colors.grey[600]),
                ),
                Text(
                  taskItem['planArrivalTime'],
                )
              ],
            ),
            Spacer(),
            Container(
                width: 80,
                height: 32,
                padding: EdgeInsets.only(
                  top: 5.5,
                ),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(16),
                    color: taskItem['enablePickUp']
                        ? Colors.red[400]
                        : Colors.red[200]),
                child: GestureDetector(
                  onTap: () {
                    // TODO: 点击提货
                  },
                  child: Text(
                    '$desc',
                    textAlign: TextAlign.center,
                    style: TextStyle(color: Colors.white, fontSize: 14),
                  ),
                )),
          ])
        ],
      ),
    );
  }
}
